package com.example.xiongmao.service.impl;

import com.example.xiongmao.entity.DTO.CommonStatus;
import com.example.xiongmao.entity.DTO.user.UserChargeDTO;
import com.example.xiongmao.entity.DTO.user.addUserChargeDTO;
import com.example.xiongmao.entity.PageResult;
import com.example.xiongmao.entity.VO.user.userChargeVO;
import com.example.xiongmao.mapper.UserChargeMapper;
import com.example.xiongmao.service.UserChargeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class userChargeServiceImpl implements UserChargeService {

    @Autowired
    private UserChargeMapper userChargeMapper;

    @Override
    public PageResult list(UserChargeDTO userChargeDTO) {
        // 设置分页参数
        PageHelper.startPage(userChargeDTO.getPage(),userChargeDTO.getPageSize());
        // 调用mapper方法进行查询
        List<userChargeVO> pageResults = userChargeMapper.list(userChargeDTO);
        Page page = (Page) pageResults;
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 添加用户
     * @param addUser
     */
    @Override
    public void add(addUserChargeDTO addUser) {
        userChargeMapper.add(addUser);
    }

    /**
     * 编辑回显
     * @param id
     * @return
     */
    @Override
    public userChargeVO getbyId(Integer id) {
        userChargeVO users = userChargeMapper.getById(id);
        return users;
    }
    /**
     * 编辑员工信息
     * @param updateUser
     */
    @Override
    public void updateUser(addUserChargeDTO updateUser) {
        userChargeMapper.updateUser(updateUser);
    }

    /**
     * （批量）删除用户信息
     * @param ids
     */
    @Override
    public void deleteBatch(List<Integer> ids) {
        userChargeMapper.deleteUserBatch(ids);
    }

    /**
     * 修改用户状态
     * @param userStatus
     */
    @Override
    public void userStatusChange(CommonStatus userStatus) {
        System.out.println("当前用户状态:"+userStatus.getStatus());
        if("1".equals(userStatus.getStatus())){
            // status==1表示正常，需要禁用==0
            userChargeMapper.userDisable(userStatus.getId());
        }else{
            // status==0表示禁用，需要正常==1
            userChargeMapper.userunDisable(userStatus.getId());
        }
    }


}
